<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<title>HTML5 websocket php test</title>
		<script type="text/javascript" src="../jquery-1.7.2.js"></script>
		<style type="text/css">
			body,
			p {
				margin: 0px;
				padding: 0px;
				font-size: 14px;
				color: #333;
				font-family: Arial, Helvetica, sans-serif;
			}

			.rin {
				width: 98%;
				margin: 5px auto;
			}


			#ct {
				margin-right: 111px;
				height: 100%;
				overflow-y: auto;
				overflow-x: hidden;
			}

			#us {
				width: 110px;
				overflow-y: auto;
				overflow-x: hidden;
				float: right;
				border-left: 1px #ccc solid;
				height: 100%;
				background-color: #F1F1F1;
			}

			#us p {
				padding: 3px 5px;
				color: #08C;
				line-height: 20px;
				height: 20px;
				cursor: pointer;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			#us p:hover,
			#us p:active,
			#us p.ck {
				background-color: #069;
				color: #FFF;
			}

			#us p.my:hover,
			#us p.my:active,
			#us p.my {
				color: #333;
				background-color: transparent;
			}

			button {
				float: right;
				width: 80px;
				height: 35px;
				font-size: 18px;
			}

			input {
				width: 100%;
				height: 30px;
				padding: 2px;
				line-height: 20px;
				outline: none;
				border: solid 1px #CCC;
			}

			.rin p {
				margin-right: 160px;
			}

			.rin span {
				float: right;
				padding: 6px 5px 0px 5px;
				position: relative;
			}

			.rin span img {
				margin: 0px 3px;
				cursor: pointer;
			}

			.rin span form {
				position: absolute;
				width: 25px;
				height: 25px;
				overflow: hidden;
				opacity: 0;
				top: 5px;
				right: 5px;
			}

			.rin span input {
				width: 180px;
				height: 25px;
				margin-left: -160px;
				cursor: pointer
			}
		</style>
	</head>

	<body>
		<div class="rin">
			<button id="sd">发送</button>
			<p><input id="nrong"></p>
		</div>
		<script>
			if (typeof(WebSocket) == 'undefined') {
				alert('你的浏览器不支持 WebSocket ，推荐使用Google Chrome 或者 Mozilla Firefox');
			}
		</script>
		<script>
			(function() {
				var key = 'all',
					mkey;
				var users = {};
				var url = 'ws://10.3.121.157:8000';
				var so = false,
					n = false;

				function st() {
					so = new WebSocket(url);
					so.onopen = function(event) {
						console.log(event)
						if (event.isTrusted) {
							so.send('type=add&ming=hhhhh&uuid=1DBF03125C7A4D75A0177DB7AAA661B0&vin=LC0CD4C49J1033328&own=0');
						}
					}

					so.onmessage = function(event) {
						console.log(event)
						console.log(event.data)
					}

					so.onclose = function(event) {
						console.log(event)
					}
				}

				$('#sd').click(function() {
					// if (!so) {
					// 	return st();
					// }
					st();
					//var masg = $('#nrong').val();
					//so.send('nr='+masg+'&key=' + key);
				})

			})(); 
		</script>
	</body>
</html>

